﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace iTunesFastForward
{

    enum LogLevel
    {
        Release,
        Debug,
        TalkALot
    }

    class Log
    {

        const string FILE_NAME = "iTFF-log.txt";
        const int MAX_FILE_SIZE = 2000000; // 2mo

        private static Log _instance = null;
        public static Log Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new Log();
                return _instance;
            }
        }

        public Log()
        {
            if (!File.Exists(FILE_NAME))
            {
                try
                {
                    File.Create(FILE_NAME).Close();
                }
                catch (Exception)
                {
                }

            }
        }

        /// <summary>
        /// Writes a line in log file
        /// </summary>
        /// <param name="text"></param>
        public void WriteLine(string text)
        {
            try
            {
                using (StreamWriter sw = File.AppendText(FILE_NAME))
                {
                    sw.WriteLine(string.Format("{0} : {1}", DateTime.Now, text));
                }
            }
            catch (Exception)
            {
            }
        }

        /// <summary>
        /// Returns the log content
        /// </summary>
        /// <returns></returns>
        public string[] GetContentAsLines()
        {
            try
            {
                return File.ReadAllLines(FILE_NAME);
            }
            catch (Exception)
            {
                return null;
            }
        }
    }
}
